package com.hollycrm.hollysqm.analyzer.solr.listener;

import com.hollycrm.hollysqm.analyzer.dic.DictionaryLoader;
import lombok.extern.log4j.Log4j;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.sql.SQLException;

/**
 * Created by zhaihw on 2016/5/4.
 * 监听，启动服务的时候加载分词器
 */
@Log4j
public class LoadDictionaryListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        try {
            log.info("load dic ....");
            DictionaryLoader.getInstance().loadUserDic();
            DictionaryLoader.getInstance().loadStopDic();
            log.info("load dic finished");
        } catch (SQLException | ClassNotFoundException e) {
            e.printStackTrace();
            log.error("load dic has error",e);
        }
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {

    }
}
